package com.soft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.soft.entity.User;
import com.soft.mapper.UserMapper;

@Service
public class UserService { 
    @Autowired
    private UserMapper userMapper;
    public List<User> queryAll(){
    	List<User> userList = userMapper.selectList(null);
    	return userList;
    }
    public List<User> queryByuserAge(String userAge){
    	QueryWrapper<User> qw = new QueryWrapper<>();
    	qw.eq("user_age",userAge);
    	List<User> userList = userMapper.selectList(qw);
    	return userList;
    }
    public int insertOne(String userName,String userAge,String userEmail) {
    	User user = new User();
    	user.setUserName(userName);
    	user.setUserAge(userAge);
    	user.setUserEmail(userEmail);
    	int num = userMapper.insert(user);
    	return num;
    }
    public int deleteById(Long userId) {
    	User user = new User();
    	user.setUserId(userId);
    	int num = userMapper.deleteById(user);
    	return num;
    }
    public int update(Long userId,String userName,String userAge,String userEmail){
		User user = new User();
		user.setUserId(userId);
		user.setUserName(userName);
		user.setUserAge(userAge);
		user.setUserEmail(userEmail);
		int num = userMapper.updateById(user);
		return num;
	}
    public List<User> queryByUserAge(String userAge){
    	QueryWrapper<User> qw = new QueryWrapper<>();
    	qw.eq("user_age", userAge);
    	List<User> userList = userMapper.selectList(qw);
    	return userList;
    }
}
